var removeElements = function(head, val) {
    if(head===null) return head;
    let newHead = new ListNode(null);
    newHead.next = head;
    let tmp = newHead;
    while(tmp.next!=null) {
        if(tmp.next.val===val) {
            tmp.next = tmp.next.next;
        }else {
            tmp = tmp.next;
        }
    }
    return newHead.next;
  
  };

//   递归
var removeElements = function(head, val) {
    if(head===null) return head;
   head.next = removeElements(head.next,val);
   return head.val===val?head.next:head;
};